package com.cdc.code;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cdc.taskhandler.R;
import com.cdc.tools.Tools;

public class CodeFragment extends Fragment{


    private static final String FILECONTENT = "fileContent";

    // TODO: Rename and change types of parameters

    private String fileContent;

    private String codeContent;

    private TextView tvCode;
    public CodeFragment() {
        // Required empty public constructor
    }


    public static CodeFragment newInstance(String param1) {
        CodeFragment fragment = new CodeFragment();
        Bundle args = new Bundle();
        args.putString(FILECONTENT, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            fileContent = getArguments().getString(FILECONTENT);
            codeContent= Tools.readFromAssets(getActivity(),fileContent);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_code, container, false);
        tvCode=view.findViewById(R.id.tvCode);
        tvCode.setMovementMethod(ScrollingMovementMethod.getInstance());
        tvCode.setText(codeContent);
        return view;
    }



    @Override
    public void onDetach() {
        super.onDetach();

    }

}
